import com.sun.awt.AWTUtilities;

import java.awt.*;
import java.awt.event.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class SimplePanel extends JFrame {
    public SimplePanel() throws IOException {
        super();
        setBackground(Color.white);
        setAlwaysOnTop(true);
        addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
                setShape(new Ellipse2D.Float(0,0,getWidth(),getHeight()));
            }
        });
        setUndecorated(true);
        setSize(100,100);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        BufferedImage img = ImageIO.read(new File("D:\\code\\swing\\src\\images\\zhifu-yue.png"));
        JPanel panel = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
            }
        };
        panel.setSize(100,100);
        add(panel);

       Point origin = new Point();
       addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                origin.x = e.getX();
                origin.y = e.getY();
                if (e.getClickCount() == 2) {
                    XTheme.prepareUI();
                    JFrame frame = new JFrame("结算平台");
                    frame.setJMenuBar(XMenuBar.createMenuBar());

                    Box vBox = Box.createVerticalBox();
                    vBox.setOpaque(false);
                    try {
                        vBox.add(XTable.createTable());
                        frame.add(vBox);
                    } catch (ClassNotFoundException ex) {
                        throw new RuntimeException(ex);
                    }

                    frame.setSize(500,400);
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

                    AWTUtilities.setWindowOpacity(frame,0.95F);
                    frame.setVisible(true);
               }
            }
        });
        addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
                Point p = getLocation();
                setLocation(p.x + e.getX() - origin.x, p.y + e.getY() - origin.y);
            }
        });

    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            SimplePanel sw = null;
            try {
                sw = new SimplePanel();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            sw.setVisible(true);
        });
    }
}
